package com.yanqu.road.logic.pb;

import com.yanqu.road.entity.autodata.task.UserObjectTaskData;
import com.yanqu.road.entity.task.UserTaskActive;
import com.yanqu.road.entity.task.UserTaskData;
import com.yanqu.road.pb.task.ObjectTaskProto;
import com.yanqu.road.pb.task.TaskProto;

import java.math.BigInteger;
import java.util.List;


public class TaskPb {

	public static TaskProto.TaskDataTempMsg.Builder parseTaskDataTempMsg(int taskId, UserTaskData userTaskData) {
		TaskProto.TaskDataTempMsg.Builder msg = TaskProto.TaskDataTempMsg.newBuilder();
		if (null == userTaskData) {
			msg.setTaskId(taskId);
			msg.setValue(BigInteger.ZERO.toString());
			msg.setState(0);
			msg.setFinishTime(0);
		} else {
			msg.setTaskId(userTaskData.getTaskId());
			msg.setValue(userTaskData.getValue().toString());
			msg.setState(userTaskData.getState());
			msg.setFinishTime(userTaskData.getFinishTime());
		}
		return msg;
	}

	public static TaskProto.TaskDataListMsg.Builder parseTaskDataListMsg(List<UserTaskData> userTaskDataList){
		TaskProto.TaskDataListMsg.Builder listMsg = TaskProto.TaskDataListMsg.newBuilder();
		if(null != userTaskDataList){
			for(UserTaskData userTaskData : userTaskDataList){
				if (userTaskData == null) {
					continue;
				}
				TaskProto.TaskDataTempMsg.Builder msg = parseTaskDataTempMsg(userTaskData.getTaskId(), userTaskData);
                listMsg.addDataList(msg);
            }
		}
		return listMsg;
	}

	public static TaskProto.TaskActiveMsg.Builder parseTaskActiveMsg(UserTaskActive userTaskActive){
		if(null == userTaskActive){
			return null;
		}
		TaskProto.TaskActiveMsg.Builder msg = TaskProto.TaskActiveMsg.newBuilder();
		msg.setTaskActive(userTaskActive.getTaskActive());
		if(null != userTaskActive.getTaskGetRewardIndexList()){
			msg.addAllRewardIndexList(userTaskActive.getTaskGetRewardIndexList());
		}
		return msg;
	}

	public static TaskProto.SevenDayActiveMsg.Builder parseSevenDayActiveMsg(UserTaskActive userTaskActive){
		if(null == userTaskActive){
			return null;
		}
		TaskProto.SevenDayActiveMsg.Builder msg = TaskProto.SevenDayActiveMsg.newBuilder();
		msg.setTaskActive(userTaskActive.getSevenDayActive());
		msg.setSevenDayStartTime(userTaskActive.getSevenDayStartTime());
		if (null != userTaskActive.getSevenDayGetRewardIndexList()) {
			msg.addAllRewardIndexList(userTaskActive.getSevenDayGetRewardIndexList());
		}
		return msg;
	}

	public static ObjectTaskProto.ObjectTaskDataTempMsg parseObjectTaskDataTempMsg(UserObjectTaskData taskData) {
		ObjectTaskProto.ObjectTaskDataTempMsg.Builder msg = ObjectTaskProto.ObjectTaskDataTempMsg.newBuilder();
		msg.setCompleteType(taskData.getCompleteType());
		msg.setObjectId(taskData.getObjectId());
		msg.addAllFinishTaskIds(taskData.getFinishIds());
		msg.setValue(taskData.getValue().toString());
		msg.setParam(taskData.getParam());
		return msg.build();
	}

	public static ObjectTaskProto.ObjectTaskDataListMsg.Builder parseObjectTaskDataListMsg(List<UserObjectTaskData> taskDataList) {
		ObjectTaskProto.ObjectTaskDataListMsg.Builder listMsg = ObjectTaskProto.ObjectTaskDataListMsg.newBuilder();
		for (UserObjectTaskData taskData : taskDataList) {
			if (taskData == null) {
				continue;
			}
			ObjectTaskProto.ObjectTaskDataTempMsg msg = parseObjectTaskDataTempMsg(taskData);
			listMsg.addDataList(msg);
		}
		return listMsg;
	}
}
